What is wrong with this "apply" function

Hi everyone, below shows a code written to use "apply" after creating "multiList"s:
 

void compareAttrNames (DBE dbe) {
 
  DB name_comparator = create "Attribute Name Comparator"
  DBE myList1, myList2, myList3
 
  void tabSelected(DBE attributeTab) {
     int tab_choice = get attributeTab
  }
 
   void attributeGet (DBE myButton1, myList1, myList2, myList3) {
   
  string AttrSet
  string attrHolder1 = get myList1
  string attrHolder2 = get myList2
  string attrHolder3 = get myList3
  
  
  
 
  print attrHolder1 "\n" attrHolder2 "\n" attrHolder3 "\n"
 
 
  if(!null attrHolder1) {
    inactive(myList2)
    inactive(myList3)
 }  
 
  if(!null attrHolder2) {
    inactive(myList1)
    inactive(myList3)
 }  
 
 if(!null attrHolder3) {
    inactive(myList1)
    inactive(myList2)
 }  
    if(!null attrHolder1)
        AttrSet = attrHolder1
    if(!null attrHolder2)
        AttrSet = attrHolder2
    if(!null attrHolder3)
        AttrSet = attrHolder3
}
 
 
  string name1, name2
  string attrHolder1 = "" , attrHolder2 = "", attrHolder3 = ""
  int idx1, idx2, idx11 = 0, idx12 = 0, idx13 = 0
  int if_detecter = 0
  int if_detecter1 = 0
 
  idx1 = get list1              // position in list
  idx2 = get list2
 
  name1 = get list1             // baseline name
  name2 = get list2
 
// This part performs actions to fill "array"s for the multiList functions.
 
 
 
DBE attributeTab   = tab(name_comparator,options,300, 200, tabSelected)
DBE myButton1      = apply(name_comparator, "Display Objects", attributeGet)
 
show name_comparator
 
}

 


problem: All actions not shown in the middle part are performed without a problem and give the correct results. And all variables are well defined, and any variable mention above declared. However whenever a choice is made in a multiList, i can not get its string value by "get" function, I tought this was owing to the fact that get function returns its value after a button is clicked. So i used "get" functions inside another void function. Nevertheless, neither i can get still return value of the "get" functions, nor code is executed. All the time, i receive an error message saying that i used incorrect arguments for "apply" function. I can not see from where this error arises.

I thank you everyone who pays attention, and i present my kind regards.

PS: The problem persists even tough i declared all DB and DBE elements globally, and also i encountered same problem when i use a "button" or "ok" function.

PSS: void attributeGet will be enhanced such that it will display objects also but for the time being as i am stucked in this problem i thought it would not make much sense to eloborate this part.

 


SystemAdmin - Tue May 19 05:34:10 EDT 2009

Re: What is wrong with this "apply" function
SystemAdmin - Tue May 19 06:23:13 EDT 2009

The callback to the apply function can have only one parameter: the calling DB.

In addition to this you can not "get" values from multiList, you have to iterate through the selected values in list, please look at the "for value in list (selected items)" in DXL Help for multiList.

Re: What is wrong with this "apply" function
llandale - Tue May 19 09:06:03 EDT 2009

Strangely, a nested function cannot use variables declared in any of its outward parent functions. A function can only use variables declared in that function or in the 'main' part of the script. In your case, your silly function 'tabSelected' could not access variable 'myList1' declared in the parent function. Anyway, this makes nested functions pretty hopeless, unless for some reason you want to have the same function name and same parameters behave differently in different (parent) functions. (This is different than nested blocks, which can indeed use variables declared in outward blocks.) This nested reality pretty much forces you to declare all your DB and DBEs in the Main near the top of your code where they can be accessed by your various callback functions.

Don't nest, its hard to read.

Yes, 'apply' functions must have exactly one parameter, a DB. Mine routinely have 'DB dbXX' parameter and never use dbXX. Yes, 'button' and 'set' callback functions must have exactly one parameter, a DBE. 'DBE dbeXX' ditto.

I don't recall the awkward realities of 'list' DBEs but the other post is no doubt correct about that. IIRC you need to 'realize' the DBE and THEN populate the lists, but maybe that's another kind of DBE.

If you want a function to fire when the user selects or de-selectes in the list, you can use the 'set' callback, perhaps:
void listWasClicked(DBE dbeList){deal with the dbeList}; and later on "set(myList1, listWasClicked)".

Nit-Picks:

Please comment the closing brace as to which thing its closing; its hard to see that the brace after your 6 'if' statements is closing function attributeGet.

I think your first 3 'if's are wrong since if more than one DBE has a value you'll end up inactivating all of them. Perhaps:
if (null attrHolder1) inactive(myList1), repeated for the other two.

I see in function attributeGet(), that you calculate variable AttrSet but its never used.

>Louie